package sasp_KML;
// Self is an exstenion of Entity and is used to house information about
// the client for transimission to the group. Self is a threaded runnable class
// to keep the GPS simulation independent of network traffic (as a GPS would
// acutally do)



import sasp_protocol.Entity;
import org.boehn.kmlframework.kml.KmlException;
import sasp_protocol.Protocol;
import java.io.IOException;

public class Self extends Entity implements Runnable{

private double[] location = new double[2];
private float[] currentdest;


// Create a new motion object to simulate the output of a GPS for the client
Motion go = new Motion();
private boolean end = false;
Protocol protocol;
// Constructor changes the alias to you to discern client on map. Also
// passes refference to the protocol class

public Self(Protocol _protocol){
	Alias = "you";
        protocol = _protocol;
   }

// starts the runnable code for the self object
public void run(){
	    

while(end == false){	
// tells the motion class to create a new destination
currentdest = go.GenDest();
// logic to tell the motion class to keep generating new locations
// until the destiation is reached.
if(go.getinc() < 0){
	while (currentdest[1] < location[1]){
	location = go.GenStep();
	latitude = location[0];
	longitude = location[1];
	go();
	try{
		Thread.sleep(10000);
	}catch(InterruptedException ex){
		ex.printStackTrace();
	}
        if(protocol.islive() == true){
       try{
            protocol.UPD_DATA(location);
    } catch (IOException Ex){
        end = true;
    } catch (KmlException Kex){
        end = true;
    }
    }
    }

}else{
	while (currentdest[1] > location[1]){
		location = go.GenStep();
		latitude = location[0];
		longitude = location[1];
		go();
	try{
		Thread.sleep(10000);
	}catch(InterruptedException ex){
		ex.printStackTrace();
	}
        }
	}
}



}


}
